package com.example.chat.controller;

import com.dragonsoftbravo.libs.Opr;
import com.dragonsoftbravo.web.PageVO;
import com.example.chat.dao.UserDao;
import com.example.chat.model.User;
import com.example.chat.model.ro.UserListRO;
import com.example.chat.model.ro.UserRo;
import com.example.chat.model.vo.UserListVO;
import com.example.chat.model.vo.UserVO;
import com.example.chat.service.UserService;
import com.example.chat.utils.ChatException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author pq
 * @date 2022/8/14 1:45
 * @description 用户管理
 * @modified
 **/
@Api(value = "用户管理", tags = {"用户管理"})
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Resource
    UserService UserService;

    @Resource
    UserDao UserDao;

    @ApiOperation(value = "新增/更新用户")
    @PostMapping("/updateUser")
    public ResponseEntity<Opr<Void>> add(@RequestBody @Valid UserRo ro, BindingResult br) {
        validateFiled(br);
        UserService.add(ro);
        return process(this::successResult);
    }

    @ApiOperation(value = "用户列表")
    @PostMapping(value = "/list")
    public ResponseEntity<Opr<Page<UserListVO>>> userList(@RequestBody UserListRO UserListRO) {
        UserDao.findUserListByPage(UserListRO);
        return processData(() -> UserDao.findUserListByPage(UserListRO), this::processException);
    }


//    @ApiOperation(value = "查询用户")
//    @PostMapping(value = "/queryUsers")
//    public ResponseEntity<Opr<Page<UserVO>>> userList(@RequestBody User User) {
//        return processData(() -> UserService.find(User), this::processException);
//    }



}
